< previous page page_19 next page >

Page 19
The ScaledCircle subroutine shown in the following code uses the Circle method to draw an ellipse using custom coordinates. It converts the desired ellipse's width and height into twips so that it can study the ellipse's dimensions as they should appear on the screen, not in the custom coordinate system. It uses these values to calculate the ellipse's aspect ratio.
Next, if the ellipse's width is greater than its height, the routine sets the ellipse's radius to half of its width converted back into the custom coordinate system. This gives the ellipse the proper width. The aspect ratio makes the ellipse adjust its height properly.
If the ellipse's height is greater than its width, the routine sets the ellipse's radius to half of its width converted back into the custom coordinate system, multiplied by the aspect ratio. This gives half the height of the ellipse converted into the drawing object's horizontal scale mode. This value and the aspect ratio make the Circle method provide the necessary ellipse.
Finally, the subroutine calls the Circle method to draw the ellipse.
e10a6a0a59f035e870d90cca05b85fce.gif
' Draw a circle stretched to obey the object's 
' scale mode. 
Private Sub ScaledCircle(ByVal obj As Object, _ 
    ByVal xmin As Single, ByVal ymin As Single, _ 
    ByVal xmax As Single, ByVal ymax As Single) 
Dim cx As Single 
Dim cy As Single 
Dim wid As Single 
Dim hgt As Single 
Dim aspect As Single 
Dim radius As Single 

    ' Find the center. 
    cx = (xmin + xmax) / 2 
    cy = (ymin + ymax) / 2 
     
    ' Get the ellipse's size in twips. 
    wid = obj.ScaleX(xmax - xmin, obj.ScaleMode, vbTwips) 
    hgt = obj.ScaleY(ymax - ymin, obj.ScaleMode, vbTwips) 
    aspect = hgt / wid 
     
    ' See which dimension is larger. 
    If wid > hgt Then 
        ' The major axis is horizontal. 
        ' Get the radius in custom coordinates. 
        radius = obj.ScaleX(wid / 2, vbTwips, obj.ScaleMode) 
    Else 
        ' The major axis is vertical. 
        ' Get the radius in custom coordinates. 
        radius = aspect * obj.ScaleX(wid / 2, vbTwips, obj.ScaleMode) 
    End If 
      
   ' Draw the circle. 
   obj.Circle (cx, cy), radius, , , , aspect 
End Sub

 
< previous page page_19 next page >